package com.hyk.commonLib.common.utils.dataBinding.bindingAdapter;

import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.BindingAdapter;

import com.hyk.commonLib.common.utils.ScreenUtils;

public class SizeAdapter {

    @BindingAdapter("layoutWidth")
    public static void setLayoutWidth(View view, float width) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.height = (int) width;
        view.setLayoutParams(params);
    }

    @BindingAdapter("layoutHeight")
    public static void setLayoutHeight(View view, float height) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.height = (int) height;
        view.setLayoutParams(params);
    }

    @BindingAdapter("layoutWidthPx")
    public static void setLayoutWidthPx(View view, float width) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.height = ScreenUtils.dp2px(width);
        view.setLayoutParams(params);
    }

    @BindingAdapter("layoutHeightPx")
    public static void setLayoutHeightPx(View view, float height) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.height = (int) height;
        view.setLayoutParams(params);
    }
}
